package com.itheima.article.controller;

import com.itheima.article.dto.ArticleInfoDto;
import com.itheima.article.pojo.ApAuthor;
import com.itheima.article.service.ApArticleService;
import com.itheima.article.service.ApAuthorService;
import com.itheima.common.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class ApiAuthorFeignController {

    @Autowired
    private ApAuthorService apAuthorService;

    @Autowired
    private ApArticleService apArticleService;
    /**
     * 通过远程调用UserId和wmUserId查询作者信息
     *
     * @param userId ，wmUserId
     * @return
     */
    @GetMapping("/api/apAuthor/getByApUserIdWmUserId/{userId}/{wmUserId}")
    public ResultVo<ApAuthor> getByApUserIdWmUserId(@PathVariable("userId") long userId, @PathVariable("wmUserId") long wmUserId) {
        ApAuthor apAuthor = apAuthorService.getByApUserIdWmUserId(userId, wmUserId);
        return ResultVo.ok(apAuthor);
    }

    /**
     * 通过远程调用添加作者信息
     *
     * @param apAuthor
     * @return
     */
    @PostMapping("/api/apAuthor/add")
    public ResultVo add(@RequestBody ApAuthor apAuthor) {
        apAuthorService.save(apAuthor);
        return ResultVo.ok();
    }


    /**
     * 同步自媒体文章到文章微服
     * @param dto
     * @return
     */
    @PostMapping("/api/apArticle/saveArticleInfo")
   public ResultVo saveArticleInfo(@RequestBody ArticleInfoDto dto){
        if (apArticleService.saveArticleInfo(dto)){
            return ResultVo.ok();
        }
        return ResultVo.error();
    }

}
